<%+header%>
<!--
    This module is a demo to configure MTK' proprietary WiFi driver.
    Basic idea is to bypass uci and edit wireless profile (mt76xx.dat) directly.
    LuCI's WiFi configuration is more logical and elegent, but it's quite tricky to
    translate uci into MTK's WiFi profile (like we did in "uci2dat").

    Hua Shao <nossiac@163.com>
-->

<%
local disp = require "luci.dispatcher"
-- local request  = disp.context.path
local request = disp.context.request
local mtkwifi = require("mtkwifi")
local devname = request[5]
local devs = mtkwifi.get_all_devs()
local dev = {}
for _,v in ipairs(devs) do
    if v.devname == devname then
        dev = v
    end
end
local cfgs = mtkwifi.load_profile(dev.profile)
local map_cfgs
local first_card_cfgs
local appliedMapModeDiff
if pcall(require, "map_helper") then
    map_cfgs = mtkwifi.load_profile(mtkwifi.__read_easymesh_profile_path())
    first_card_cfgs = mtkwifi.load_profile(mtkwifi.detect_first_card())
    local appliedMapDiffTable = mtkwifi.diff_profile(mtkwifi.detect_first_card())
    appliedMapModeDiff = appliedMapDiffTable["MapMode"] and appliedMapDiffTable["MapMode"][2] or nil
end
%>

<script src="/luci-static/resources/monCon.js"></script>
<script type="text/javascript" src="<%=resource%>/cbi.js?v=git-17.250.41546-90ac861"></script>
<script type="text/javascript">
function hi(to) {
    var a;
    var x;
    var tabs = new Array();
    tabs.push("basic");
    <% if cfgs["VOW_Airtime_Fairness_En"] then %>
        tabs.push("vow");
    <% end %>
    for (x in tabs)
    {
        if (tabs[x] != to) {
            a = document.getElementById('dev-cfg' + '-tab-' + tabs[x]);
            a.className = "cbi-tab-disabled";
            a = document.getElementById('dev-cfg' + '-' + tabs[x]);
            a.style.display = "none";
        }
    }
    a = document.getElementById('dev-cfg' + '-tab-' + to);
    a.className = "cbi-tab";
    a = document.getElementById('dev-cfg' + '-' + to);
    a.style.display = "";
}
</script>

<form method="post" name="cbi" action="<%=luci.dispatcher.build_url("admin", "mtk", "wifi", "chip_cfg", devname)%>" enctype="multipart/form-data" onreset="return cbi_validate_reset(this)" onsubmit="return cbi_validate_form(this, 'Some fields are invalid, cannot save values!') && ValidateAllSettings()" autocomplete="false">
    <fieldset class="cbi-section">
        <legend> Chip Configurations - <%=string.split(devname,".")[1]%>
            <%local diff = mtkwifi.diff_profile(dev.profile)%>
            <%if next(diff) ~= nil then%>
                <span style="color:red;">( <a href="javascript:location.href='<%=luci.dispatcher.build_url("admin", "mtk", "wifi", "reload", dev.devname)%>'">Click here</a> to apply changes)</span>
            <%end%>
        </legend>
        <div class="alert-message" id="EASYMESH_WARNING_MSG" style="display:none;">
            <strong>WARNING: EasyMesh feature is enabled!</strong>
        </div>
        <ul class="cbi-tabmenu">
            <li class="cbi-tab" id="dev-cfg-tab-basic">
                <a href="javascript:hi('basic');this.blur(); ">Basic</a>
            </li>
            <% if cfgs["VOW_Airtime_Fairness_En"] then %>
                <li class="cbi-tab-disabled" id="dev-cfg-tab-vow">
                    <a href="javascript:this.blur(); hi('vow')">VoW</a>
                </li>
            <% end %>
        </ul>
        <table id="dev-cfg-basic" class="cbi-section-table">
            <tr>
                <td>Decline BA Request</td>
                <td>
                    <input type="radio" name="HT_BADecline" value="1" <% if cfgs.HT_BADecline == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="HT_BADecline" value="0" <% if cfgs.HT_BADecline == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <tr>
                <td>Reverse Direction Grant (RDG)</td>
                <td>
                    <input type="radio" name="HT_RDG" value="1" <% if cfgs.HT_RDG == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="HT_RDG" value="0" <% if cfgs.HT_RDG == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <tr>
                <td>BA Win size</td>
                <td>
                    <input name="HT_BAWinSize" id="HT_BAWinSize" value="<%=cfgs.HT_BAWinSize%>"/><% if string.split(cfgs.WirelessMode,";")[1] == "16" or string.split(cfgs.WirelessMode,";")[1] == "17" or string.split(cfgs.WirelessMode,";")[1] == "18" then %> (range 1-256) <% else %> (range 1-64) <% end %>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>HT Disallow TKIP</td>
                <td>
                    <input type="radio" name="HT_DisallowTKIP" value="1" <% if cfgs.HT_DisallowTKIP == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="HT_DisallowTKIP" value="0" <% if cfgs.HT_DisallowTKIP == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <% if cfgs.WHNAT then %>
                <tr>
                    <td>Wi-Fi HW NAT</td>
                    <td>
                        <select style="width:auto" name="WHNAT">
                            <option value="1" <% if cfgs.WHNAT == "1" then %> selected="selected"<% end%>> Enable</option>
                            <option value="0" <% if cfgs.WHNAT ~= "1" then %> selected="selected"<% end%>> Disable</option>
                        </select>
                    </td>
                    <td>Supported by MT7615</td>
                </tr>
            <% end %>
            <% if cfgs.E2pAccessMode then %>
                <tr>
                    <td>E2pAccessMode</td>
                    <td>
                        <select style="width:auto" name="E2pAccessMode">
                            <option value="1" <% if cfgs.E2pAccessMode == "1" then %> selected="selected"<% end%>>EFUSE</option>
                            <option value="2" <% if cfgs.E2pAccessMode == "2" then %> selected="selected"<% end%>>FLASH</option>
                            <% if mtkwifi.__is_6890_project() then %>
                                <option value="4" <% if cfgs.E2pAccessMode == "4" then %> selected="selected"<% end%>>BIN</option>
                            <% end %>
                        </select>
                    </td>
                    <td></td>
                </tr>
            <% end %>
            <tr>
                <td>Beacon Interval</td>
                <td>
                    <input name="BeaconPeriod" id="BeaconPeriod" value="<%=cfgs.BeaconPeriod%>" />tu(range 20-999, default 100)
                </td>
                <td></td>
            </tr>
            <tr>
                <td>Data Beacon Rate (DTIM)</td>
                <td>
                    <input name="DtimPeriod" id="DtimPeriod" value="<%=cfgs.DtimPeriod%>" />Beacon interval(range 1-255, default 1)
                </td>
                <td></td>
            </tr>
            <tr>
                <td>BG Protection Mode</td>
                <td>
                    <select name="BGProtection" style="width:auto">
                        <option value="0" <% if cfgs.BGProtection == "0" then %>selected="selected"<% end %>>Auto</option>
                        <option value="1" <% if cfgs.BGProtection == "1" then %>selected="selected"<% end %>>Always On</option>
                        <option value="2" <% if cfgs.BGProtection == "2" then %>selected="selected"<% end %>>Always Off</option>
                    </select>
                </td>
                <td></td>
            </tr>
            <tr>
                <td>Short Preamble</td>
                <td>
                    <input type="radio" name="TxPreamble" value="1" <% if cfgs.TxPreamble == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="TxPreamble" value="0" <% if cfgs.TxPreamble == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <tr>
                <td>TX Burst</td>
                <td>
                    <input type="radio" name="TxBurst" value="1" <% if cfgs.TxBurst == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="TxBurst" value="0" <% if cfgs.TxBurst == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <tr>
                <td>Packet Aggregate</td>
                <td>
                    <input type="radio" name="PktAggregate" value="1" <% if cfgs.PktAggregate == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="PktAggregate" value="0" <% if cfgs.PktAggregate == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
            <tr>
                <td>Short Slot</td>
                <td>
                    <input type="radio" name="ShortSlot" value="1" <% if cfgs.ShortSlot == "1" then %> checked="checked"<% end %>/> Enable
                    <input type="radio" name="ShortSlot" value="0" <% if cfgs.ShortSlot == "0" then %> checked="checked"<% end %>/> Disable
                </td>
                <td></td>
            </tr>
        </table>

        <% if cfgs["VOW_Airtime_Fairness_En"] then %>
            <div id="dev-cfg-vow" style="display:none">
                <fieldset class="cbi-section">
                    <legend> <a name="apcli_scan_section">Air-time Fairness (ATF)</a></legend>

                    <p><b>This allows you to control how the stations assiciated with a SSID share the air-time. So it is a sort of QoS scheme for wireless stations.</b></p>
                    <p>There are 2 modes available:</p>
                    <ol>
                        <li>All stations share air-time equally.</li>
                        <li>Stations will be divide into several groups, and we cab assign different air-time ration to those groups.</li>
                    </ol>

                    <input type="hidden" id="VOW_Airtime_Fairness_En" name="VOW_Airtime_Fairness_En" value="<%=cfgs.VOW_Airtime_Fairness_En or 0%>"/>
                    <% if cfgs.VOW_Airtime_Fairness_En == "1" then %>
                    <div class="cbi-button cbi-button-remove" value="1" style="width:200px" onclick="toggle_atf(this);">
                        Disable ATF
                    </div>
                    <% else %>
                    <div class="cbi-button cbi-button-add" value="0" style="width:200px" onclick="toggle_atf(this);">
                        Enable ATF
                    </div>
                    <% end %>
                    <!-- <p>
                        <button class="cbi-button cbi-button-add"  style="width:200px" onclick="return false;">
                            Weighted Airtime Fairness
                        </button>
                    </p> -->

                </fieldset>
                <fieldset class="cbi-section">
                    <legend> <a name="apcli_scan_section">Air-time Control (ATC)</a></legend>
                    <p><b>When you have multiple SSID enabled, this allows you to control how these SSIDs share airtime. So this is a sort of QoS scheme for SSID.</b></p>
                    <p>There are 2 aspects you can control, If you enable both, the rules will merge togehter:</p>
                    <ol>
                        <li>by Throughput Quota</li>
                        <li>by Airtime Ratio</li>
                    </ol>

                    <input type="hidden" id="VOW_BW_Ctrl" name="VOW_BW_Ctrl" value="<%=cfgs.VOW_BW_Ctrl or 0%>"/>
                    <% if cfgs.VOW_BW_Ctrl == "1" then %>
                    <p class="cbi-button cbi-button-remove"  style="width:200px" value="1" onclick="toggle_atc(this);">
                        Disable ATC
                    </p>
                    <% else %>
                    <p class="cbi-button cbi-button-add" style="width:200px" value="0" onclick="toggle_atc(this);">
                        Enable ATC
                    </p>
                    <% end %>

                    <br/>
                    <!--
                    VOW_Rate_Ctrl_En
                    VOW_Group_Min_Rate
                    VOW_Group_Max_Rate

                    VOW_Airtime_Ctrl_En
                    VOW_Group_Min_Ratio
                    VOW_Group_Max_Ratio
                    -->
                    <table id="atc-table" <% if cfgs.VOW_BW_Ctrl ~= "1" then %>style="display: none;" <% end %>>
                        <tr>
                            <th>SSID</th>
                            <th>ATC</th>
                            <th>Min</th>
                            <th>Max</th>
                        </tr>
                        <%
                        for _,vif in ipairs(dev.vifs) do
                        %>
                        <tr>
                            <td rowspan="2"><img src="/luci-static/resources/icons/wifi_big.png" style="float:left; margin-right:10px"><%=vif.__ssid%></td>
                            <td>
                                <input type="checkbox" name="__atc_vif<%=vif.vifidx%>_tp" value="1" 
                                <% if vif.__atc_tp == "1"  then %>checked="checked"<% end %>>
                                <label style="margin: 0 1em;">TP
                            </td>
                            <td>
                                <input type="text" class="shortinput" name="__atc_vif<%=vif.vifidx%>_min_tp" value="<%=vif.__atc_min_tp%>"> Mbps
                            </td>
                            <td>
                                <input type="text" class="shortinput" name="__atc_vif<%=vif.vifidx%>_max_tp" value="<%=vif.__atc_max_tp%>"> Mbps
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="checkbox" name="__atc_vif<%=vif.vifidx%>_at" value="1" 
                                <% if vif.__atc_at == "1" then %>checked="checked"<% end %>>
                                <label style="margin: 0 1em;">AT</label>
                            </td>
                            <td>
                                <input type="text" class="shortinput" name="__atc_vif<%=vif.vifidx%>_min_at" value="<%=vif.__atc_min_at%>"> %
                            </td>
                            <td>
                                <input type="text" class="shortinput" name="__atc_vif<%=vif.vifidx%>_max_at" value="<%=vif.__atc_max_at%>"> %
                            </td>
                        </tr>

                        <%
                        end
                        %>
                    </table>

                </fieldset>
                <fieldset class="cbi-section">
                    <legend> <a name="apcli_scan_section">Apply to RX</a></legend>
                    <p>a
                    <b>By default, ATF and ATC only work for TX(transmit). This option will apply ATF and ATC to RX (receive).</b>
                    </p>
                    <p>
                        <input type="checkbox" name="VOW_RX_En" value="1" <% if cfgs.VOW_RX_En == "1" then %> checked="checked"<%end%>> Apply both ATC &amp; ATF to RX
                    </p>
                </fieldset>
            </div>
        <% end %>

    <div class="cbi-page-actions">

        <input class="cbi-button cbi-button-apply" name="__apply" value="Save and Apply" type="submit">
        <input class="cbi-button cbi-button-apply" value="Save" type="submit">
        <input class="cbi-button cbi-button-reset" value="Reset" type="reset">

    </div>
</form>

<script type="text/javascript">

    function ValidateAdvancedSettings()
    {
        var tmpVal = document.getElementById("HT_BAWinSize").value;
        <% if string.split(cfgs.WirelessMode,";")[1] == "16" or string.split(cfgs.WirelessMode,";")[1] == "17" or string.split(cfgs.WirelessMode,";")[1] == "18" then %>
            if(isNaN(tmpVal) || !/^\d{1,3}$/.test(tmpVal) || parseInt(tmpVal) < 1 || parseInt(tmpVal) > 256){
                alert("BA Win SIze is incorrect!\nPlease enter an integer number between 1 to 256 inclusive.");
                document.getElementById("HT_BAWinSize").focus();
                document.getElementById("HT_BAWinSize").select();
                return false;
            }
        <% else %>
            if(isNaN(tmpVal) || !/^\d{1,2}$/.test(tmpVal) || parseInt(tmpVal) < 1 || parseInt(tmpVal) > 64){
                alert("BA Win Size is incorrect!\nPlease enter an integer number between 1 to 64 inclusive.");
                document.getElementById("HT_BAWinSize").focus();
                document.getElementById("HT_BAWinSize").select();
                return false;
            }
        <% end %>
        tmpVal = document.getElementById("BeaconPeriod").value;
        if(isNaN(tmpVal) || !/^\d{2,3}$/.test(tmpVal) || parseInt(tmpVal) < 20 || parseInt(tmpVal) > 999){
            alert("Beacon Interval is incorrect!\nPlease enter an integer number between 20 to 999 inclusive.");
            document.getElementById("BeaconPeriod").focus();
            document.getElementById("BeaconPeriod").select();
            return false;
        }
        tmpVal = document.getElementById("DtimPeriod").value;
        if(isNaN(tmpVal) || !/^\d{1,3}$/.test(tmpVal) || parseInt(tmpVal) < 1 || parseInt(tmpVal) > 255){
            alert("Data Beacon Rate (DTIM) is incorrect!\nPlease enter an integer number between 1 to 255 inclusive.");
            document.getElementById("DtimPeriod").focus();
            document.getElementById("DtimPeriod").select();
            return false;
        }

        return true;
    }

    function ValidateAllSettings(){
        if( !ValidateAdvancedSettings() ){
            return false;
        }
        return true;
    }

    function toggle_atf(o) {
        if (o.getAttribute("value") == "1") {
            document.getElementById("VOW_Airtime_Fairness_En").value = "0";
            o.setAttribute("value", "0");
            o.className = "cbi-button cbi-button-add";
            o.innerHTML = "Enable ATC";
        } else {
            document.getElementById("VOW_Airtime_Fairness_En").value = "1";
            o.setAttribute("value", "1");
            o.className = "cbi-button cbi-button-remove";
            o.innerHTML = "Disable ATC";
        }
    }

    function toggle_atc(o) {
        if (o.getAttribute("value") == "1") {
            document.getElementById("VOW_BW_Ctrl").value = "0";
            o.setAttribute("value", "0");
            o.className = "cbi-button cbi-button-add";
            o.innerHTML = "Enable ATC";
            document.getElementById("atc-table").style.display = "none";
        } else {
            document.getElementById("VOW_BW_Ctrl").value = "1";
            o.setAttribute("value", "1");
            o.className = "cbi-button cbi-button-remove";
            o.innerHTML = "Disable ATC";
            document.getElementById("atc-table").style.display = "";
        }
    }

    function update_easymesh_profile_fields(obj_1905)
    {
        var vifsMacList=[];
        var WirelessModeListJS = {};

        <% for _,vif in ipairs(dev.vifs) do %>
            <% if vif.state == "up" then%>
                <% local bssid = vif.__bssid and vif.__bssid:sub(1,17) or ""%>
                <% if bssid and bssid ~= "" then %>
                    vifsMacList.push("<%=bssid%>");
                    WirelessModeListJS['<%=bssid%>'] = {};
                    <% for wModeIdx, wModeStr in pairs(dev.WirelessModeList) do %>
                        WirelessModeListJS['<%=bssid%>']['<%=wModeIdx%>'] = "<%=wModeStr%>";
                    <% end %>
                <% end %>
            <% end %>
        <% end %>


        if(!obj_1905.hasOwnProperty('Radio Info')){
            console.log("Topology does not have Radio Info Property!",obj_1905);
            return;
        }

        var wmode_span = document.getElementById("EASY_MESH_WMODE_SPAN");
        wmode_span.innerHTML = document.getElementById("WirelessMode").value;
        var channel_span = document.getElementById("EASY_MESH_CHANNEL_SPAN");

        if (!channel_span){
            console.log("Failed to update EasyMesh channel field! Could not find the channel to update!");
            return;
        }
        for (var vifIdx = 0; vifIdx < vifsMacList.length; vifIdx++){
            var radioIdx;
            for (radioIdx=0; radioIdx < obj_1905['Radio Info'].length; radioIdx++){
                var radioInfoObj = obj_1905['Radio Info'][radioIdx];
                var bssInfoArr = radioInfoObj['BSSINFO'];
                var bssIdx;
                for(bssIdx=0; bssIdx < bssInfoArr.length; bssIdx++){
                    var bssInfo = bssInfoArr[bssIdx];
                    if(bssInfo.hasOwnProperty('BSSID') && (bssInfo['BSSID'].toUpperCase() == vifsMacList[vifIdx].toUpperCase())){
                        channel_span.innerHTML = radioInfoObj['channel'];
                        document.getElementById("DEV_CFG_BASIC_SETTINGS").style.display = "none";
                        document.getElementById("EASY_MESH_DEV_SETTINGS_TBODY").style.display = "";
                        break;
                    }
                }
                if(bssIdx < bssInfoArr.length){
                    break;
                }
            }
            if(radioIdx < obj_1905['Radio Info'].length){
                break;
            }
        }
    }

    function find_own_topo_info(devRole, jsTopoInfo, alMac)
    {
        var tree_info = [];
        var topoInfoArr = jsTopoInfo['topology information'];
        if(!(topoInfoArr instanceof Array)){
            console.log("Incorrect TopologyInfo: Value of topology information is not an Array!");
            return;
        }
        for(var idx_1905=0; idx_1905 < topoInfoArr.length; idx_1905++){
            var obj_1905 = topoInfoArr[idx_1905];
            if (obj_1905.hasOwnProperty('AL MAC') && (obj_1905['AL MAC'].toUpperCase() == alMac.toUpperCase())){
                update_easymesh_profile_fields(obj_1905);
                return;
            }
        }
        console.log(alMac," AL-MAC NOT FOUND in Topology! Topology: ",jsTopoInfo);
    }

    function get_al_mac(devRole, jsTopoInfo)
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "mtk", "multi_ap", "get_al_mac")%>' + '/' + devRole, null,
            function(x)
            {
                console.log(x);
                try{
                    var r = JSON.parse(x.response);
                    var mac_reg_exp = /[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}:[A-Fa-f0-9]{2}/;
                    if (r['status'] == "SUCCESS" && mac_reg_exp.test(r['al_mac'])) {
                        find_own_topo_info(devRole, jsTopoInfo, r['al_mac']);
                    }
                    else{
                        console.log("Incorrect AL-MAC received!",r['status'],r['al_mac']);
                    }
                }
                catch(e){
                    console.log("Incorrect response received for get AL-MAC request!",e.name,e.message);
                }
            }
        );
    }

    function get_run_time_topology(devRole)
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "mtk", "multi_ap", "get_runtime_topology")%>', null,
            function(x)
            {
                try{
                    var r = JSON.parse(x.response);
                    if(r.status == "SUCCESS"){
                        var jsTopoInfo = JSON.parse(r['luaTopologyInfo']);
                        get_al_mac(devRole, jsTopoInfo);
                    }
                    else{
                        console.log("Failed to get Topology Info!\nStatus: ",r.status);
                    }
                }
                catch(e){
                    console.log("Incorrect response! Failed to get Topology Info!",e.name,e.message);
                }
            }
        );
    }

    function get_device_role()
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "mtk", "multi_ap", "get_device_role")%>', null,
            function(x)
            {
                console.log(x);
                try{
                    var devRoleObj = JSON.parse(x.response);
                    var devRole = parseInt(devRoleObj.mapDevRole);
                    if(devRole != 1 && devRole != 2){
                        console.log("EasyMesh Device Role is neither Controller nor Agent!");
                        return;
                    }
                    document.getElementById("EASYMESH_WARNING_MSG").style.display = "";
                    get_run_time_topology(devRole);
                }
                catch(e){
                    console.log("Incorrect response received for get device role request!",e.name,e.message);
                }
            }
        );
    }

    function check_update_easymesh_profile()
    {
        <% if not pcall(require, "map_helper") then %>
            console.log("map_helper library is not available!");
            return;
        <% else %>
            <%if not map_cfgs then %>
                console.log("EasyMesh Configurations are not available!");
                return;
            <% else %>
                <% if (not appliedMapModeDiff and first_card_cfgs.MapMode == "1") or
                    (appliedMapModeDiff and appliedMapModeDiff == "1" and first_card_cfgs.MapMode ~= "1") then %>
                    get_device_role();
                <% end %>
            <% end %>
        <% end %>
    }

    function get_apply_status_cb(rsp)
    {
        try{
            var r = JSON.parse(rsp);
        }
        catch(e){
            return;
        }
        if(r.status == "ON_PROGRESS"){
            var u = confirm("Device is applying the saved settings now!\n" +
                "It is recommended to wait until all the saved settings are applied.\n" +
                "Please click on 'OK' button to wait for the device.\n" +
                "or click on 'Cancel' button to configure the settings available in current web-page.");
            if (u == true) {
                location = '<%=luci.dispatcher.build_url("admin", "mtk", "wifi", "loading")%>' + window.location.pathname;
            }
        }
    }

    function get_apply_status()
    {
        XHR.get('<%=luci.dispatcher.build_url("admin", "mtk", "wifi", "get_apply_status")%>', null,
            function(x)
            {
                console.log(x);
                get_apply_status_cb(x.response);
            }
        );
    }

    window.onload = function() {
        MonCon.ping();
        get_apply_status();
        check_update_easymesh_profile();
    }

</script>

<%+footer%>
